package com.ac.util.sms;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;

public class TencentSMS {
	
	
	private static String contentStr = "000";//提醒短信模板id
	private static String loginStr = "000";//验证码模板id
	
	public static boolean sendLogin(String phone,String num) {
		return sendSMS(phone,num,loginStr);
	}
	
	public static boolean sendContent(String phone,String content) {
		return sendSMS(phone,content,contentStr);
	}
	
	private static boolean sendSMS(String phone,String content,String type) {
		boolean isSend = false;
		try {
        	Credential cred = new Credential("123", "456");
        	HttpProfile httpProfile = new HttpProfile();
        	httpProfile.setReqMethod("POST");
        	httpProfile.setConnTimeout(60);
        	httpProfile.setEndpoint("sms.tencentcloudapi.com");
        	ClientProfile clientProfile = new ClientProfile();
        	clientProfile.setSignMethod("HmacSHA256");
        	clientProfile.setHttpProfile(httpProfile);
			SmsClient client = new SmsClient(cred, "ap-guangzhou",clientProfile);
			SendSmsRequest req = new SendSmsRequest();
			String sdkAppId = "123";
			req.setSmsSdkAppId(sdkAppId);
			String signName = "三十六艺";
			req.setSignName(signName);
			String senderid = "";
			req.setSenderId(senderid);
			String sessionContext = "";
			req.setSessionContext(sessionContext);
			String extendCode = "";
			req.setExtendCode(extendCode);
			String templateId = type;
			req.setTemplateId(templateId);
			String[] phoneNumberSet = {"+86"+phone };
			req.setPhoneNumberSet(phoneNumberSet);
			String[] templateParamSet = { content };
			req.setTemplateParamSet(templateParamSet);
			SendSmsResponse res = client.SendSms(req);
			String resStr = SendSmsResponse.toJsonString(res);
			if(resStr.indexOf("send success")!=-1) {
				isSend = true;
			}
//			System.out.println(resStr);
       } catch (Exception e) {
      }
      return isSend;
	}
	
	public static void main(String[] args) {
		boolean isSend = sendContent("15117635634", "测试");
		System.out.println(isSend);
	}
	
}